﻿namespace MDXStudio
{
    using MDXStudio.QueryEditor;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FindDialog : Form
    {
        private Button btnFindCancel;
        private Button btnFindNext;
        private ComboBox comboFind;
        private IContainer components;
        private Label lblFindWhat;
        private int m_PrevFind;
        public MdxEditor m_TextBox;

        public FindDialog()
        {
            this.InitializeComponent();
            this.m_PrevFind = 0;
        }

        private void btnFindCancel_Click(object sender, EventArgs e)
        {
            int selectionStart = this.m_TextBox.SelectionStart;
            this.m_TextBox.SelectAll();
            this.m_TextBox.SelectionBackColor = SystemColors.Window;
            this.m_TextBox.SelectionStart = selectionStart;
            this.m_TextBox.Focus();
            base.Close();
        }

        private void btnFindNext_Click(object sender, EventArgs e)
        {
            int num = this.m_TextBox.Text.IndexOf(this.comboFind.Text, this.m_PrevFind, StringComparison.InvariantCultureIgnoreCase);
            if (num >= 0)
            {
                this.m_TextBox.SelectAll();
                this.m_TextBox.SelectionBackColor = SystemColors.Window;
                this.m_TextBox.SelectionColor = SystemColors.WindowText;
                this.m_TextBox.SelectionStart = num;
                this.m_TextBox.SelectionLength = this.comboFind.Text.Length;
                this.m_TextBox.SelectionBackColor = Color.Blue;
                this.m_TextBox.SelectionColor = Color.White;
                this.m_TextBox.Focus();
                this.m_TextBox.ScrollToCaret();
                this.m_PrevFind = num + 1;
            }
            base.Focus();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.lblFindWhat = new Label();
            this.comboFind = new ComboBox();
            this.btnFindNext = new Button();
            this.btnFindCancel = new Button();
            base.SuspendLayout();
            this.lblFindWhat.AutoSize = true;
            this.lblFindWhat.Location = new Point(10, 12);
            this.lblFindWhat.Name = "lblFindWhat";
            this.lblFindWhat.Size = new Size(0x38, 13);
            this.lblFindWhat.TabIndex = 0;
            this.lblFindWhat.Text = "Find what:";
            this.comboFind.FormattingEnabled = true;
            this.comboFind.Location = new Point(13, 0x1c);
            this.comboFind.Name = "comboFind";
            this.comboFind.Size = new Size(0x134, 0x15);
            this.comboFind.TabIndex = 1;
            this.btnFindNext.Location = new Point(0x7b, 0x40);
            this.btnFindNext.Name = "btnFindNext";
            this.btnFindNext.Size = new Size(0x68, 0x17);
            this.btnFindNext.TabIndex = 2;
            this.btnFindNext.Text = "&Find Next";
            this.btnFindNext.UseVisualStyleBackColor = true;
            this.btnFindNext.Click += new EventHandler(this.btnFindNext_Click);
            this.btnFindCancel.DialogResult = DialogResult.Cancel;
            this.btnFindCancel.Location = new Point(0xea, 0x40);
            this.btnFindCancel.Name = "btnFindCancel";
            this.btnFindCancel.Size = new Size(0x57, 0x17);
            this.btnFindCancel.TabIndex = 3;
            this.btnFindCancel.Text = "&Cancel";
            this.btnFindCancel.UseVisualStyleBackColor = true;
            this.btnFindCancel.Click += new EventHandler(this.btnFindCancel_Click);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.CancelButton = this.btnFindCancel;
            base.ClientSize = new Size(0x14d, 0x63);
            base.Controls.Add(this.btnFindCancel);
            base.Controls.Add(this.btnFindNext);
            base.Controls.Add(this.comboFind);
            base.Controls.Add(this.lblFindWhat);
            base.Name = "FindDialog";
            base.ShowIcon = false;
            this.Text = "Find";
            base.ResumeLayout(false);
            base.PerformLayout();
        }
    }
}

